import React, { useEffect, useState } from 'react';
import DescriptionsCondition from '@/components/DescriptionsCondition';
import DrawerCondition from '@/components/DrawerCondition';
import PopImgShow from '@/components/PopImgShow';
import TableDataBlock from '@/components/TableDataBlock';
import { add_type, workType_status } from '@/common/contact'

import { Collapse, Card } from 'antd'
const commissionTable = (props) => {
  const { adminCommissionList = [], adminCommissionSnapshotList = [], stageSnapshotList = [], stageSnapshot = {}, stageInfo = {}, stage, showType = '0', adminFinishStatus, adminRepeatFlag, devAdminCommissionList
    = [] } = props
  const renderFinishFlag = () => {
    if (adminFinishStatus === '1') {
      return '(达标)'
    } else if (adminFinishStatus === '0' && adminRepeatFlag === '0') {
      return '(未达标)'
    } else if (adminFinishStatus === '0' && adminRepeatFlag === '1') {
      return '(重新达标中)'
    } else return ''
  }
  const tabList = [
    {
      key: 'adminCommissionList',
      show: adminCommissionList.length > 0,
      tab: '已结算佣金',
    },
    {
      key: 'adminCommissionSnapshotList',
      show: adminCommissionSnapshotList.length > 0,

      tab: '已确认佣金',
    },



    {
      key: 'stageSnapshot',
      show: stageSnapshotList.length,
      // show: stage === 'sells' || stage === 'service',
      tab: '待确认佣金',
    },
    {
      key: 'devAdminCommissionList',
      show: devAdminCommissionList.length > 0,
      tab: '研发佣金',
    },

  ];

  const [active, setActive] = useState(adminCommissionList.length > 0 ? 'adminCommissionList' : adminCommissionSnapshotList.length > 0 ? 'adminCommissionSnapshotList' : 'stageSnapshot')
  const getColumns = [
    // {
    //   title: '业绩',
    //   children: [
    //     {
    //       title: '阶段业绩比例(%)',
    //       align: 'center',
    //       dataIndex: 'stagePerformancePercentage',
    //     },
    //     {
    //       title: '阶段业绩',
    //       align: 'center',
    //       dataIndex: 'stagePerformance',
    //     },
    //     {
    //       title: '分配业绩比例(%)',
    //       align: 'center',
    //       dataIndex: 'performancePercentage',
    //     },
    //     {
    //       title: '分配业绩',
    //       align: 'center',
    //       dataIndex: 'performance',
    //     },
    //   ]
    // },
    {
      title: '阶段',
      align: 'center',
      dataIndex: 'stageInfo',
      render: ({ stageName }) => {
        return stageName
      }
    },
    {
      title: '创建时间',
      align: 'center',
      dataIndex: 'createTime',
    },
    {
      title: '阶段佣金比例(%)',
      align: 'center',
      dataIndex: 'stageCommissionPercentage',
    },
    {
      title: '阶段佣金',
      align: 'center',
      dataIndex: 'stageCommission',
    },
    {
      title: '阶段扣除佣金',
      align: 'center',
      dataIndex: 'stageDeductCommission',
    },
    {
      title: '分配阶段佣金比例(%)',
      align: 'center',
      dataIndex: 'commissionPercentage',
    },
    {
      title: '分配佣金',
      align: 'center',
      dataIndex: 'commission',
    },
    {
      title: '分配阶段扣除佣金',
      align: 'center',
      dataIndex: 'deductCommission',
    },
    {
      title: '实际佣金',
      align: 'center',
      dataIndex: 'realCommission',
    },
    {
      title: '佣金归属人',
      align: 'center',
      dataIndex: 'adminName',
    },
    {
      title: '阶段核验扣除比例(%)',
      align: 'center',
      dataIndex: 'stageCheckDeductCommissionPercent',
    },
    {
      title: '阶段核验扣除金额',
      align: 'center',
      dataIndex: 'stageCheckDeductCommission',
    },
    {
      title: '核验扣除金额',
      align: 'center',
      dataIndex: 'checkDeductCommission',
    },

    {
      title: '负责类型',
      align: 'center',
      dataIndex: 'workType',
      render: (e) => {
        return workType_status[e]
      }

    },

    {
      title: '阶段类型',
      dataIndex: 'stageType',
      render: (e) => {
        return {
          normal: '常规', directSell: '直接成交', repurchase: '追销'
        }[e]
      }
    }
  ]
  const getAdminColumns = [
    // {
    //   title: '业绩',
    //   children: [
    //     {
    //       title: '阶段业绩比例(%)',
    //       align: 'center',
    //       dataIndex: 'stagePerformancePercentage',
    //     },
    //     {
    //       title: '阶段业绩',
    //       align: 'center',
    //       dataIndex: 'stagePerformance',
    //     },
    //     {
    //       title: '分配业绩比例(%)',
    //       align: 'center',
    //       dataIndex: 'performancePercentage',
    //     },
    //     {
    //       title: '分配业绩',
    //       align: 'center',
    //       dataIndex: 'performance',
    //     },
    //   ]
    // },
    {
      title: '佣金',
      children: [
        {
          title: '业务类型',
          align: 'center',
          dataIndex: 'stageType',
          render: (e) => {
            return {
              normal: "常规业务",
              directSell: '签单',
              skipAdminFinish: '忽略达标',
              repurchase: '常规业务'
            }[e]
          }
        },
        {
          title: '阶段',
          align: 'center',
          dataIndex: 'stageInfo',
          render: ({ stageName }) => {
            return stageName
          }
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '阶段佣金比例(%)',
          align: 'center',
          dataIndex: 'stageCommissionPercentage',
        },
        {
          title: '阶段佣金比例(%)',
          align: 'center',
          dataIndex: 'stageCommissionPercentage',
        },
        {
          title: '阶段佣金',
          align: 'center',
          dataIndex: 'stageCommission',
        },
        {
          title: '阶段扣除佣金',
          align: 'center',
          dataIndex: 'stageDeductCommission',
        },
        {
          title: '分配阶段佣金比例(%)',
          align: 'center',
          dataIndex: 'commissionPercentage',
        },
        {
          title: '分配佣金',
          align: 'center',
          dataIndex: 'commission',
        },
        {
          title: '分配阶段扣除佣金',
          align: 'center',
          dataIndex: 'deductCommission',
        },
        {
          title: '实际佣金',
          align: 'center',
          dataIndex: 'realCommission',
        },
        {
          title: '佣金归属人',
          align: 'center',
          dataIndex: 'adminName',
        },

        {
          title: '阶段核验扣除比例(%)',
          align: 'center',
          dataIndex: 'stageCheckDeductCommissionPercent',
        },
        {
          title: '阶段核验扣除金额',
          align: 'center',
          dataIndex: 'stageCheckDeductCommission',
        },
        {
          title: '核验扣除金额',
          align: 'center',
          dataIndex: 'checkDeductCommission',
        },

      ]
    },
    {
      title: '结算',
      children: [
        {
          title: '结算月份',
          align: 'center',
          dataIndex: 'commissionSettleMonth',
        },
        {
          title: '发放月份',
          align: 'center',
          dataIndex: 'commissionCreditedMonth',
        },
      ]
    },
  ]
  const devGetColumns = [
    {
      title: '阶段',
      align: 'center',
      dataIndex: 'stageInfo',
      render: ({ stageName }) => {
        return stageName
      }
    },
    {
      title: '创建时间',
      align: 'center',
      dataIndex: 'createTime',
    },
    {
      title: '阶段佣金比例(%)',
      align: 'center',
      dataIndex: 'stageCommissionPercentage',
    },
    {
      title: '阶段佣金',
      align: 'center',
      dataIndex: 'stageCommission',
    },
    {
      title: '阶段扣除佣金',
      align: 'center',
      dataIndex: 'stageDeductCommission',
    },
    {
      title: '分配阶段佣金比例(%)',
      align: 'center',
      dataIndex: 'commissionPercentage',
    },
    {
      title: '分配佣金',
      align: 'center',
      dataIndex: 'commission',
    },
    {
      title: '分配阶段扣除佣金',
      align: 'center',
      dataIndex: 'deductCommission',
    },
    {
      title: '实际佣金',
      align: 'center',
      dataIndex: 'realCommission',
    },
    {
      title: '佣金归属人',
      align: 'center',
      dataIndex: 'adminName',
    },
    {
      title: '阶段核验扣除比例(%)',
      align: 'center',
      dataIndex: 'stageCheckDeductCommissionPercent',
    },
    {
      title: '阶段核验扣除金额',
      align: 'center',
      dataIndex: 'stageCheckDeductCommission',
    },
    {
      title: '核验扣除金额',
      align: 'center',
      dataIndex: 'checkDeductCommission',
    },

    {
      title: '负责类型',
      align: 'center',
      dataIndex: 'workType',
      render: (e) => {
        return workType_status[e]
      }

    },

    {
      title: '阶段类型',
      dataIndex: 'stageType',
      render: (e) => {
        return {
          normal: '常规', directSell: '直接成交', repurchase: '追销'
        }[e]
      }
    }
  ]
  const stageSnapshotColumns = [
    // {
    //   title: '业绩',
    //   children: [
    //     {
    //       title: '阶段业绩比例(%)',
    //       align: 'center',
    //       dataIndex: 'stagePerformancePercentage',
    //     },

    //     {
    //       title: '阶段业绩',
    //       align: 'center',
    //       dataIndex: 'stagePerformance',

    //     },
    //   ]
    // },
    {
      title: '阶段',
      align: 'center',
      dataIndex: 'stageInfo',
      render: ({ stageName }) => {
        return stageName
      }
    },
    {
      title: '创建时间',
      align: 'center',
      dataIndex: 'createTime',
    },
    {
      title: '阶段佣金比例(%)',
      align: 'center',
      dataIndex: 'stageCommissionPercentage',
    },
    {
      title: '阶段佣金',
      align: 'center',
      dataIndex: 'stageCommission',
    },
    {
      title: '阶段扣除佣金',
      align: 'center',
      dataIndex: 'stageDeductCommission',
    },

    {
      title: '阶段核验扣除比例(%)',
      align: 'center',
      dataIndex: 'stageCheckDeductCommissionPercent',
    },
    {
      title: '阶段核验扣除金额',
      align: 'center',
      dataIndex: 'stageCheckDeductCommission',
    },
  ]
  const { stageName } = stageInfo
  const contentList = {
    adminCommissionList: <TableDataBlock
      bordered
      pagination={false}
      columns={getAdminColumns}
      list={adminCommissionList}
      rowKey={(record) => `${record.orderSn}`}
    ></TableDataBlock>,
    adminCommissionSnapshotList: <TableDataBlock
      bordered
      pagination={false}
      columns={getColumns}
      list={adminCommissionSnapshotList}
      rowKey={(record) => `${record.orderSn}`}
    ></TableDataBlock>,
    stageSnapshot: <TableDataBlock
      bordered
      pagination={false}
      columns={stageSnapshotColumns}
      list={stageSnapshotList}
      rowKey={(record) => `${record.orderSn}`}
    ></TableDataBlock>,
    devAdminCommissionList: <TableDataBlock
      bordered
      pagination={false}
      columns={devGetColumns}
      list={devAdminCommissionList}
      rowKey={(record) => `${record.id}`}
    ></TableDataBlock>
  };

  const onChange = (key) => {
    setActive(key);
  };
  return (
    <Card
      title={stageName + `${renderFinishFlag()}`}
      activeTabKey={active}
      onTabChange={(key) => {
        onChange(key);
      }}
      tabList={tabList.filter(item => {
        const { show = true } = item
        if (show) {
          return true
        }
        return false
      })}
    >
      {/* {contentList[active]} */}
      </Card>
  );
};
export default commissionTable
